package com.yuan.SMS.controller;

import com.alibaba.fastjson.JSON;
import com.yuan.SMS.dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
@RestController
public class AddressCountController {
    @Autowired
    StudentDao addressCdao;

    @RequestMapping("/addressCount")
    @CrossOrigin("http://localhost:8080")
    public String addressCount(String address) {
        System.out.println(address);
        int i = addressCdao.getStudentCounts();
        int j = addressCdao.getStudentCountsByAddress(address);
        double perc = j / i;
        HashMap<String, Object> res = new HashMap<>();
        if (i != 0.00) {
            res.put("flag", "success");
            res.put("data", perc);
        } else {
            res.put("flag", "error");
        }
        return JSON.toJSONString(res);
    }
}
